﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using frag_boardgame;

namespace frag_testproject
{
    /// <summary>
    /// Summary description for TestConfiguration
    /// </summary>
    [TestClass]
    public class TestConfiguration
    {
       
        public TestConfiguration()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        //
        // You can use the following additional attributes as you write your tests:
        //
        // Use ClassInitialize to run code before running the first test in the class
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // Use ClassCleanup to run code after all tests in a class have run
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // Use TestInitialize to run code before running each test 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // Use TestCleanup to run code after each test has run
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        [TestInitialize]
        public void ConfigurationInitilize()
        {
            
        }
        [TestMethod]
        public void TestRowColsConfiguration()
        {
            Configuraion conf = new Configuraion();
            Assert.AreEqual<int>(16, conf.Rows);
            Assert.AreEqual<int>(25, conf.Cols);

            conf.Cols = 0;
            conf.Rows = 0;
            Assert.AreEqual<int>(16, conf.Rows);
            Assert.AreEqual<int>(25, conf.Cols);

            conf.Cols = 5;
            conf.Rows = 5;
            Assert.AreEqual<int>(5, conf.Rows);
            Assert.AreEqual<int>(5, conf.Cols);
            

        }

        [TestMethod]
        public void TestBoardConfiguration()
        {
            Configuraion conf = new Configuraion(new GameConfiguration(20, 20, 2));
            

            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(-1, -1, "Ron"));
            conf.addPlayer(new PlayerConfiguration(-1, -1, "Bob"));

            game.New(conf);
            game.StartGame();
            Assert.AreEqual<int>(20, game.Data.Board.Height);
            Assert.AreEqual<int>(20, game.Data.Board.Width);

        }

        [TestMethod]
        public void TestPlayersPos()
        {
            Configuraion conf = new Configuraion();
           
            Game game = new Game();
            conf.addPlayer(new PlayerConfiguration(5, 5, "Ron"));
            conf.addPlayer(new PlayerConfiguration(8, 8, "Bob"));

            game.New(conf);
            game.StartGame();
            Assert.AreNotEqual(null, game.Data.Board.GetSquare(5, 5).player);
            Assert.AreNotEqual(null, game.Data.Board.GetSquare(8, 8).player);

            conf = new Configuraion(new GameConfiguration(10, 10, 2));
            conf.addPlayer(new PlayerConfiguration(-1, -1, "Ron"));
            conf.addPlayer(new PlayerConfiguration(-1, -1, "Bob"));

            game.New(conf);
            game.StartGame();
            int count = 0;
            Board board = game.Data.Board;
            for (int row = 0; row < board.Height; row++)
            {
                for (int col = 0; col < board.Width; col++)
                {
                    if (board.GetSquare(row, col).player != null)
                        count++;
                }
            }
            Assert.AreEqual<int>(2, count);


            
            
            
        }

       
    }
}
